<%@ page language="Java" import="java.util.*,descriptor.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<%
	CompaniesListDescriptor compList = (CompaniesListDescriptor)request.getAttribute("Companies");
	RecruitersListDescriptor recruiterDes = (RecruitersListDescriptor)request.getAttribute("RecruiterDes");
	CompanySupsListDescriptor supervisorDes = (CompanySupsListDescriptor)request.getAttribute("SupervisorDes");
	String companyID = (String)request.getAttribute("companyID");
	String addOffers = (String)request.getAttribute("addOffers");
	String error1 = (String)request.getAttribute("error1");
	String error2 = (String)request.getAttribute("error2");
	String notif = "";
	if(error1 != null)
	{
		notif = "<p style=\"color:red; font-size: 10px;\">" + error1 + "</p>";
	}

%>

<html>
	<jsp:include page="CareerHeader.jsp" >
		<jsp:param name="pageTitle" value="Work Placement Management System - Career Officer" />
	</jsp:include>
	<body  OnLoad="showmenu(document.getElementById('smenu5'));">
		<jsp:include page="CareerPageHeader.jsp"></jsp:include> 
		<div id="container">
			<jsp:include page="CareerMenu.jsp" ></jsp:include>
			<div id="content">
				<h3 class="posttitle">Career Officer - Add a Offer</h3>
				<div class="entry">
					<%= notif %>
					<%
							int sizeList = compList.sizeCompaniesList(); 
							if(sizeList > 0)
							{
					%>
					<p>Select a company in the list to add an offer</p>
					<br>
					<form name="frmcompanyList" method="post" style="margin-left: auto; margin-right: auto;">
						<input type="hidden" name="action" value="addOffer1"> 
						<select OnChange="document.frmcompanyList.submit();" name="companyID">  
							<option value="">Select a company: </option>  
					<%
								
								for(int i=0; i<sizeList; i++)
								{
									String compName = compList.getCompanyDescriptors().get(i).getName();
									int compID = compList.getCompanyDescriptors().get(i).getId();
									String selected = "";
									if(companyID !=null && Integer.parseInt(companyID) == compID)
									{
										selected = "selected";
									}
					%>
							<option value="<%= compID %>" <%= selected %>><%= compName %></option>
					<%			
								}
					%>
						</select>
					</form>
					<br>
					<hr>
					<%
							}
							else
							{ 
								if(error1 != null)
					%>
									<p><%= error1 %></p>
					<%	
							} 
							
							if(addOffers != null)
							{
								if(addOffers.equals("1") && recruiterDes != null && supervisorDes != null)
								{
					%>
							<form method="post">
								<input type="hidden" name="action" value="addedOffer">
								<fieldset>
									<legend>Offer's Details</legend>
									<fieldset>
										<legend>Offer</legend>
										<input type="hidden" name="companyID" value="<%= companyID %>">
										<p>Name: <input type="text" name="CompOfferName"></p>
										<p>Description: <br>
											<textarea name="CompOfferDescription" rows="5" cols="60"> ... </textarea>
										</p>
										<fieldset>
											<legend>Recruiter and Supervisor</legend>
											<p> Select a Recruiter for this offer :
											<select name="recruiterID">  
												<option value="-1">Select a recruiter: </option>  
										<%
													int size1 = recruiterDes.sizeRecruitersList();
													for(int i=0; i<size1; i++)
													{
														String recruiterName = recruiterDes.getRecruiterDescriptors().get(i).getName() + " "+ recruiterDes.getRecruiterDescriptors().get(i).getFirstName();
														int recID = recruiterDes.getRecruiterDescriptors().get(i).getUserId();
										%>
												<option value="<%= recID %>"><%= recruiterName %></option>
										<%			
													}
										%>
												<option value="-1">No Recruiter</option>  
											</select>
											</p>
											<p> Select a Supervisor for this offer :
											<select name="supervisorID">  
												<option value="-1">Select a supervisor: </option>  
										<%
													int size2 = supervisorDes.getCompanySupDescriptors().size();
													for(int i=0; i<size2; i++)
													{
														String supervisorName = supervisorDes.getCompanySupDescriptors().get(i).getName() + " "+ supervisorDes.getCompanySupDescriptors().get(i).getFirstName();
														int supID = supervisorDes.getCompanySupDescriptors().get(i).getUserId();
										%>
												<option value="<%= supID %>"><%= supervisorName %></option>
										<%			
													}
										%>
												<option value="-1">No Supervisor</option>  
											</select>
											</p>
										</fieldset>
										<fieldset>
											<legend>Expiry Date</legend>
											<p>Available from: <input type="text" id="calendar1" name="calendar1"><button type="button" id="trigger1">Choose the date</button>
											    <script type="text/javascript">//<![CDATA[
											      Zapatec.Calendar.setup({
											        firstDay          : 1,
											        range             : [2008.01, 2999.12],
											        electric          : false,
											        inputField        : "calendar1",
											        button            : "trigger1",
											        ifFormat          : "%A, %B %d, %Y",
											        daFormat          : "%Y/%m/%d"
											      });
											    //]]></script>
											
											<br/>
											</p>
											<p>To:<input type="text" id="calendar2" name="calendar2"> <button type="button" id="trigger2">Choose the date</button>
											    <script type="text/javascript">//<![CDATA[
											      Zapatec.Calendar.setup({
											        firstDay          : 1,
											        range             : [2008.01, 2999.12],
											        electric          : false,
											        inputField        : "calendar2",
											        button            : "trigger2",
											        ifFormat          : "%A, %B %d, %Y",
											        daFormat          : "%Y/%m/%d"
											      });
											    //]]></script>
											<br/>
										</fieldset>
									</fieldset>
								<fieldset>
									<p><button type="submit">Add Offer</button> <button type="reset">Clear</button></p>
								</fieldset>
							</form>	
					<% 			
								}
							}
							else
							{
								if(error2 != null)
								{				
					%>
									<p style="color:red; font-size: 10px;"><%= error2 %></p>
					<%
								}
							}	
					%>
					
				</div>
	    	</div>
			<jsp:include page="CareerPageFooter.jsp"></jsp:include>
		</div>	
	</body>
</html>